package org.framework.dao.plugin;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.framework.session.RequestContex;

public class DataTablesUtil {
	
	private static final String ACTION = "<div class=\"hidden-sm hidden-xs action-buttons\">"+
												"<a class=\"blue\" href=\"javascript:void(0)\" onclick=showDetail('@@@') title=\"查询详细信息\">"+
													"<i class=\"ace-icon fa fa-search-plus bigger-130\"></i>"+
												"</a>"+
												/*"<a class=\"green\" href=\"#\">"+
													"<i class=\"ace-icon fa fa-pencil bigger-130\"></i>"+
												"</a>"+*/
												"<a class=\"red\" href=\"javascript:void(0)\" onclick=removeItem('%%%%') title=\"删除信息\">"+
													"<i class=\"ace-icon fa fa-trash-o bigger-130\"></i>"+
												"</a>"+
											"</div>";
	
	private static final String ACTION2 = "<div class=\"hidden-sm hidden-xs action-buttons\">"+
													"<a class=\"red\" href=\"javascript:void(0)\" onclick=downloadItem('%%%%') title=\"文件下载\">"+
													"<i class=\"ace-icon fa fa-cloud-download bigger-130\"></i>"+
												"</a>"+
												"<a class=\"red\" href=\"javascript:void(0)\" onclick=commitItem('%%%%') title=\"提交信息\">"+
												"<i class=\"ace-icon fa fa-file-text bigger-130\"></i>"+
											"</a>"+
												"</div>";
	
	private static final String ACTION3 = "<div class=\"hidden-sm hidden-xs action-buttons\">"+
												"<a class=\"red\" href=\"javascript:void(0)\" onclick=downloadItem('%%%%') title=\"文件下载\">"+
												"<i class=\"ace-icon fa fa-cloud-download bigger-130\"></i>"+
											"</a>"+
											"</div>";
	
	private static final String ACTION4 = "<div class=\"hidden-sm hidden-xs action-buttons\">"+
													"<a class=\"blue\" href=\"javascript:void(0)\" onclick=showDetail('@@@') title=\"查询详细信息\">"+
														"<i class=\"ace-icon fa fa-search-plus bigger-130\"></i>"+
													"</a>"+
													"<a class=\"red\" href=\"javascript:void(0)\" onclick=commitItem('%%%%') title=\"提交信息\">"+
													"<i class=\"ace-icon fa fa-file-text bigger-130\"></i>"+
												"</a>"+
													"<a class=\"red\" href=\"javascript:void(0)\" onclick=removeItem('%%%%') title=\"删除信息\">"+
													"<i class=\"ace-icon fa fa-trash-o bigger-130\"></i>"+
												"</a>"+
												"</div>";
	
	private static final String ACTION5 = "<div class=\"hidden-sm hidden-xs action-buttons\">"+
													"<a class=\"blue\" href=\"javascript:void(0)\" onclick=showDetail('@@@') title=\"查询详细信息\">"+
														"<i class=\"ace-icon fa fa-search-plus bigger-130\"></i>"+
													"</a>"+
													"<a class=\"red\" href=\"javascript:void(0)\" onclick=commitItem('%%%%') title=\"提交信息\">"+
													"<i class=\"ace-icon fa fa-file-text bigger-130\"></i>"+
												"</a>"+
												"</div>";
	
	private static final String ACTION6 = "<div class=\"hidden-sm hidden-xs action-buttons\">"+
													"<a class=\"blue\" href=\"javascript:void(0)\" onclick=showDetail('@@@') title=\"查询详细信息\">"+
														"<i class=\"ace-icon fa fa-search-plus bigger-130\"></i>"+
													"</a>"+
												"</div>";
	
	private static final String ACTION7 = "<div class=\"hidden-sm hidden-xs action-buttons\">"+
													"<a class=\"blue\" href=\"javascript:void(0)\" onclick=showDetail('@@@') title=\"查询详细信息\">"+
														"<i class=\"ace-icon fa fa-search-plus bigger-130\"></i>"+
													"</a>"+
													"<a class=\"red\" href=\"javascript:void(0)\" onclick=commitItem('%%%%') title=\"提交信息\">"+
													"<i class=\"ace-icon fa fa-file-text bigger-130\"></i>"+
												    "</a>"+
												"</div>";
	
	private static final String ACTION8 = "<div class=\"hidden-sm hidden-xs action-buttons\">"+
													"<a class=\"red\" href=\"javascript:void(0)\" onclick=downloadItem('%%%%') title=\"文件下载\">"+
													"<i class=\"ace-icon fa fa-cloud-download bigger-130\"></i>"+
												"</a>"+
												"<a class=\"red\" href=\"javascript:void(0)\" onclick=commitItem('%%%%') title=\"提交信息\">"+
												"<i class=\"ace-icon fa fa-file-text bigger-130\"></i>"+
											    "</a>"+
													"<a class=\"red\" href=\"javascript:void(0)\" onclick=removeItem('%%%%') title=\"删除信息\">"+
													"<i class=\"ace-icon fa fa-trash-o bigger-130\"></i>"+
												"</a>"+
												"</div>";
										
	
	private static final String CHECKBOX = "<label class=\"pos-rel\">"+
												"<input type=\"checkbox\" class=\"ace\"/>"+
												"<span class=\"lbl\"></span>"+
											"</label>";
	
	private static final String RADIO = "<label class=\"pos-rel\">"+
											"<input type=\"radio\" class=\"ace\"/>"+
											"<span class=\"lbl\"></span>"+
										"</label>";
	
	
	public static <T> Map<String, Object> buildDataTablesReturn(List<T> list) {
		Page page = PageContext.getPage();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("aaData", list);
		map.put("iTotalRecords", page.getTotalCount());
		map.put("iTotalDisplayRecords", page.getTotalCount());
		HttpServletRequest request = RequestContex.getRequest();
		map.put("sEcho", request.getParameter("sEcho"));
		return map;
	}
	
	
	public static String actionBtn(String... pid){
		String pk = Arrays.toString(pid).replace("[","").replace("]","");
		return new String(ACTION).replace("@@@", pk).replace("%%%%",pk);
	}
	
	public static String actionBtn2(String... pid){
		String pk = Arrays.toString(pid).replace("[","").replace("]","");
		return new String(ACTION2).replace("@@@", pk).replace("%%%%",pk);
	}
	
	public static String actionBtn3(String... pid){
		String pk = Arrays.toString(pid).replace("[","").replace("]","");
		return new String(ACTION3).replace("@@@", pk).replace("%%%%",pk);
	}
		
	public static String actionBtn4(String... pid){
		String pk = Arrays.toString(pid).replace("[","").replace("]","");
		return new String(ACTION4).replace("@@@", pk).replace("%%%%",pk);
	}
	
	
	public static String actionBtn5(String... pid){
		String pk = Arrays.toString(pid).replace("[","").replace("]","");
		return new String(ACTION5).replace("@@@", pk).replace("%%%%",pk);
	}
	
	public static String actionBtn6(String... pid){
		String pk = Arrays.toString(pid).replace("[","").replace("]","");
		return new String(ACTION6).replace("@@@", pk).replace("%%%%",pk);
	}
	

	public static String actionBtn7(String... pid){
		String pk = Arrays.toString(pid).replace("[","").replace("]","");
		return new String(ACTION7).replace("@@@", pk).replace("%%%%",pk);
	}
	
	public static String actionBtn8(String... pid){
		String pk = Arrays.toString(pid).replace("[","").replace("]","");
		return new String(ACTION8).replace("@@@", pk).replace("%%%%",pk);
	}
	
	
	public static String checkboxBtn(){
		return CHECKBOX;
	}
	
	public static String radioBtn(){
		return RADIO;
	}
	
	
	
	
}
